package com.woniuxy.system.controller;


import com.woniuxy.response.ResponseResult;
import com.woniuxy.system.demol.entity.Perms;
import com.woniuxy.system.service.PermsService;
import com.woniuxy.util.CheckTokenUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author why
 * @since 2023-09-08
 */
@RestController
@RequestMapping("/perms")
public class PermsController {
    @Resource
    private PermsService permsService;

    //查找所有普通的权限信息
    @GetMapping("/findAllPerms/{account}")
    public ResponseResult<List<Perms>> findAllPerms(@PathVariable("account") String account, HttpServletRequest request){
        String aid = request.getHeader("access_token");
        Map<String, Object> cUser = CheckTokenUtil.getUser(aid);
        Integer i = (Integer) cUser.get("uid");
        List<Perms> list =   permsService.findAllPerms(account);
//        List<Perms> list = permsService.list();
        return new  ResponseResult<>( ResponseResult.SUCCESS,"success",list);

    }
    //查找所有普通的权限信息
    @GetMapping("/findAllPermsSp/{account}")
    public ResponseResult<List<Perms>> findAllPermsSp(@PathVariable("account") String account){

        List<Perms> list =   permsService.findAllPermsSp(account);
        return new  ResponseResult<>( ResponseResult.SUCCESS,"success",list);

    }
    //根据用户的id，去查找部门id，再根据部门id查看有的权限
    @GetMapping("/findByUid/{id}")
    private ResponseResult<List<Perms>> findByUid(@PathVariable("id") Integer id){
        List<Perms> list=  permsService.findByUid(id);
        return new ResponseResult<>(ResponseResult.SUCCESS,"success",list);
    }

}

